//
//  ShellHomeViewController.m
//  ShellWallert
//
//  Created by lvzhao on 2019/5/13.
//  Copyright © 2019 吕VV. All rights reserved.
//

#import "ShellHomeViewController.h"
#import "ShellHomeView.h"
#import "ShellHomeViewModel.h"
#import "ShellTotalRewardModel.h"
#import "ShellWallertManager.h"
#import "LZBaseTabBarViewController.h"

@interface ShellHomeViewController ()

@property (nonatomic,strong) ShellHomeView *homeView;

@property (nonatomic,strong) ShellHomeViewModel *viewModel;

@end

@implementation ShellHomeViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    [self setupUI];
    
    [[ShellWallertManager sharedInstance] checkVersion:YES];
    
    @weakify(self);
    [[[NSNotificationCenter defaultCenter] rac_addObserverForName:k_APPLanguageWillChangeNotificationName object:nil] subscribeNext:^(NSNotification * _Nullable x) {
        @strongify(self);
        self.title = LZLocalizedString(@"矿池");
    }];
    
 
    //登陆成功;
    [[[NSNotificationCenter defaultCenter] rac_addObserverForName:k_APPLoginSuccessNotificationName object:nil] subscribeNext:^(NSNotification * _Nullable x) {
          @strongify(self);
        [self.viewModel getHashAward];
    }];
    
    [self.viewModel getHashAward];

    
//     [[RACSignal interval:5.0 onScheduler:[RACScheduler mainThreadScheduler]]subscribeNext:^(NSDate * _Nullable x) {
//           @strongify(self)
//
//           dispatch_async(dispatch_get_main_queue(), ^{
//               @strongify(self)
//               ShellTotalRewardModel *rewardModel = [ShellTotalRewardModel new];
//               [self.viewModel.reloadSubject sendNext:rewardModel];
//
//           });
//       }];
    
    
    BOOL isNotification = [LZToolCache boolForKey:@"isNotification"];
    if (isNotification) {
        LZBaseTabBarViewController *tabBarController = (LZBaseTabBarViewController *)LZTool.currentViewController.tabBarController;
        tabBarController.selectedIndex = 1;
        [LZToolCache setBool:NO forKey:@"isNotification"];
    }

    
}

- (void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
    // 这里最好调用一下这个方法，防止界面跳转时，轮播图卡在一半。。。
//    [self.homeView viewWillAppear];
    
    //算力, 信用分
    [self.viewModel getReadAccount];
    [self.viewModel getStaticInfo:YES];
}

#pragma mark - setupUI
- (void)setupUI{
        
    [self.view addSubview:self.homeView];
    [self.homeView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.edges.mas_equalTo(0);
    }];
    
}



#pragma mark - actions

#pragma mark - custool

#pragma mark - get && set
- (ShellHomeView *)homeView{
 
    if(!_homeView){
        _homeView = [[ShellHomeView alloc] initViewModel:self.viewModel];
    }
    return _homeView;
}

- (ShellHomeViewModel *)viewModel{
    if(!_viewModel){
        _viewModel = [[ShellHomeViewModel alloc] init];
        
    }
    return _viewModel;
}


/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
